﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Brewmaster
{
    /// <summary>
    /// Represents a command button with an arrow that acts as a popup menu activator.
    /// </summary>
    public partial class MenuButton : Button
    {

        private ContextMenuStrip menuStrip;

        private int arrowSize = 3;

        /// <summary>
        /// The shortcut menu to display when the user clicks the control.
        /// </summary>
        public ContextMenuStrip MenuStrip
        {
            get
            {
                return menuStrip;
            }
            set
            {
                menuStrip = value;
            }
        }

        /// <summary>
        /// The size of the downward triangle arrow drawn on the control.
        /// </summary>
        public int ArrowSize
        {
            get
            {
                return arrowSize;
            }
            set
            {
                if (value > 0)
                {
                    arrowSize = value;
                    this.Invalidate();
                }
            }
        }

        protected override bool ShowFocusCues
        {
            get
            {
                return false;
            }
        }

        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = "";
            }
        }

        public MenuButton()
        {
            InitializeComponent();
            this.Click += new EventHandler(this_Click);
        }

        private void this_Click(object sender, EventArgs e)
        {
            if (this.MenuStrip != null) {
                this.MenuStrip.Show(this, 0, this.Height);
            }
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            Point[] trianglePoints = { new Point(this.Width / 2 - (this.ArrowSize + 1), this.Height / 2 - this.ArrowSize), new Point(this.Width / 2 + (this.ArrowSize + 1), this.Height / 2 - this.ArrowSize), new Point(this.Width / 2, this.Height / 2 + this.ArrowSize)};
            pe.Graphics.FillPolygon (new SolidBrush (this.ForeColor), trianglePoints);
        }
    }


}
